{extend name="extra@admin/content"}

{block name="content"}

<form onsubmit="return false;" action="__SELF__" data-auto="true" method="post" class='layui-form' style='padding-top:20px'>
    <div class="layui-form-item">
        <label class="layui-form-label">业务类型</label>
        <div class="layui-input-block" >
          <input type="radio" lay-filter="test" name="is_duizhang" value="1"  title="暂不对账" >
          <input type="radio" lay-filter="test" name="is_duizhang" value="2"  title="确认对账" >
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" style="color:#ff5722;font-size:16px;">原料</label>
             <div class="layui-input-inline" >
                 <input type="text" name="title_1" readonly class="layui-input" value="" style="border:0px;color:#ff5722;">
             </div>
             <div class="layui-input-inline" >
                  {if condition="$order.type eq 1"}
                  <input type="text" name="title_2"  readonly class="layui-input" value="购货数量" style="border:0px;color:#ff5722;font-size:16px;">
                  {else /}
                  <input type="text" name="title_2"  readonly class="layui-input" value="生成用量" style="border:0px;color:#ff5722;font-size:16px;">
                  {/if}
             </div>
             <div class="layui-input-inline" >
                 <input type="text" name="title_2"  readonly class="layui-input" value="实际变更" style="border:0px;color:#ff5722;font-size:16px;">
             </div>
             <div class="layui-input-inline" >
                 <input type="text" name="title_3"  readonly class="layui-input" value="差异数" style="border:0px;color:#ff5722;font-size:16px;">
             </div>
             <div class="layui-input-inline" >
                 <input type="text" name="title_3"  readonly class="layui-input" value="交易单价" style="border:0px;color:#ff5722;font-size:16px;">
             </div>
             <div class="layui-input-inline" >
                 <input type="text" name="title_3"  readonly class="layui-input" value="交易总价" style="border:0px;color:#ff5722;font-size:16px;">
             </div>
        </div>
    </div>
    {foreach name="list" item="v" key="k"}
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">原料</label>
                <div class="layui-input-inline" >
                    <input type="text" name="name[]" required="required" placeholder="" autocomplete="off" readonly class="layui-input" value="{$v.name}   /{$v.unit}">
                </div>
                <div class="layui-input-inline" >
                    <input type="text" name="del_num[]" required="required" readonly placeholder="" autocomplete="off" class="layui-input" value="{$v.del_num}">
                </div>
                <div class="layui-input-inline" >
                    <input type="text" name="res_num[]" required="required" placeholder="请输入实际变更数量" autocomplete="off" class="layui-input" onblur="count_res_num(this);" value="{$v.res_num}" {if condition="$order.is_duizhang neq 0"} readonly {/if}>
                </div>
                <div class="layui-input-inline" >
                    <input type="text" name="dif_num[]" required="required" readonly placeholder="差异数"  autocomplete="off" class="layui-input" value="" >
                </div>
                <div class="layui-input-inline" >
                    <input type="text" name="r_s_price[]" required="required"  placeholder="交易单价"  autocomplete="off" class="layui-input" value="" >
                </div>
                <div class="layui-input-inline" >
                    <input type="text" name="r_price[]" required="required"  placeholder="交易总价"  autocomplete="off" class="layui-input" value="" >
                </div>
                <input type="hidden" name="id[]" value="{$v.id}">
                <input type="hidden" name="stock[]" value="{$v.stock}">
                <input type="hidden" name="material_id[]" value="{$v.material_id}">
                <input type="hidden" name="price[]" value="{$v.price}">
            </div>
        </div>
    {/foreach}
    <div class="hr-line-dashed" id="add"></div>
    <div class="col-sm-4 col-sm-offset-2">
        <div class="layui-form-item text-center">
            <input type="hidden" name="order_id" value="{$id}">
            <input type="hidden" name="order_type" value="{$order.type}">
            <a  href="javascript:history.back(-1)" class='layui-btn' style="background:#ff5722;">返回</a>
            <button class="layui-btn" type="submit" >保存</button>
        </div>
    </div>
    <script type="text/javascript">
    layui.use('form', function(){
        var form = layui.form;      //只有执行了这一步，部分表单元素才会自动修饰成功
        form.render();
    });

    /**
     *  计算小计
     * @param obj
     */
    function count_res_num(obj){
        var del_num = $(obj).parent().parent().find('input[name="del_num[]"]').val();
        var dif_num = parseInt($(obj).val())-parseInt(del_num);
        $(obj).parent().parent().find('input[name="dif_num[]"]').val(dif_num);
    }

    </script>
</form>

{/block}